#1、搜索骨科—>点击搜索—>点击出来的第一个链接—>断言文本内容
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
class SearchName:
    def __init__(self,driver):
        self.driver = driver
        self.driver.get("http://www.bjhospital.net/")
        self.driver.maximize_window()
        driver.implicitly_wait(15)
    def input_orthopedics(self,text:str):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,"keyword"))).send_keys(text)
    def click_search_button(self):
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'btn')))[0].click()
    def click_result_one(self):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[4]/ul/li[1]/div[1]/h5/a"))).click()

    def assert_text_result(self):
        win = self.driver.window_handles
        self.driver.switch_to.window(win[-1])
        text_result = WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH,"/html/body/div[3]/div/div/article/div[2]/p[1]/span[1]"))).text
        print(text_result)
        assert text_result in "毕节市第一人民医院即将进行高值医用耗材网上阳光平台议价采购工作，因涉及议价高值医用耗材品类较多，工作繁杂，为确保议价工作顺利开展，现将议价相关基本信息提前进行意向公开，请满足要求的潜在供应商提前作好相关议价准备。正式议价公告将于近期发布在中国政府采购网、贵州省招标投标公共服务平台、毕节市第一人民医院官网，请各位潜在供应商注意关注后续相关公告信息。"
    def quit(self):
        self.driver.quit() #退出浏览器

if __name__ == '__main__':
    driver = webdriver.Chrome()
    bro = SearchName(driver)  # 实例化对象
    bro.input_orthopedics("骨科")  # 点击王长帅
    bro.click_search_button() # 点击百度
    bro.click_result_one() #点击百度出来的第一个内容

    bro.assert_text_result() # 断言是否通过
    bro.quit() # 退出浏览器